| Conditions | 2 | 
| Paths | 2 | 
| Total Lines | 58 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** | ||
| 18 | 	var HttpService = function (config) { | ||
| 19 | |||
| 20 | /** Constructor */ | ||
| 21 | var ocrConfig; | ||
| 22 | 		config !== undefined ? ocrConfig = config : console.error('OCR config is not defined.'); | ||
|  | |||
| 23 | |||
| 24 | /** | ||
| 25 | * | ||
| 26 | * @private | ||
| 27 |          * @param {Object} opts (opts.data, opts.method, opts.url) | ||
| 28 |          * @returns {$.Deferred.Promise} resolve with response or reject in case of error | ||
| 29 | */ | ||
| 30 | 		var makeRequest = function (opts) { | ||
| 31 | return $.ajax(opts); | ||
| 32 | } | ||
| 33 | |||
| 34 | /** | ||
| 35 | * Load all languages that are supported form the backend. | ||
| 36 | * @public | ||
| 37 |          * @returns {$.Deferred} | ||
| 38 | */ | ||
| 39 | 		this.loadAvailableLanguages = function () { | ||
| 40 | var languages = ['deu', 'eng']; | ||
| 41 | // TODO: enable docker behavior | ||
| 42 | 			/*OCP.AppConfig.getValue('ocr', 'available-languages', '', function (data) { | ||
| 43 |                 languages = data.split(';'); | ||
| 44 | });*/ | ||
| 45 | return languages; | ||
| 46 | } | ||
| 47 | |||
| 48 | /** | ||
| 49 | * Triggers the OCR process for the given files and languages. | ||
| 50 | * @public | ||
| 51 |          * @returns {$.Deferred} | ||
| 52 | */ | ||
| 53 | 		this.process = function (selectedFiles, selectedLanguages) { | ||
| 54 | 			return makeRequest({ | ||
| 55 | method: 'POST', | ||
| 56 | url: ocrConfig.PROCESSING_ENDPOINT, | ||
| 57 | 				data: { | ||
| 58 | files: selectedFiles, | ||
| 59 | languages: selectedLanguages | ||
| 60 | }, | ||
| 61 | }); | ||
| 62 | } | ||
| 63 | |||
| 64 | /** | ||
| 65 | * Check for the status of the OCR process. | ||
| 66 | * @public | ||
| 67 |          * @returns {$.Deferred} | ||
| 68 | */ | ||
| 69 | 		this.checkStatus = function () { | ||
| 70 | 			return makeRequest({ | ||
| 71 | method: 'GET', | ||
| 72 | url: ocrConfig.STATUS_ENDPOINT, | ||
| 73 | }); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 96 | 
This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function: